#!/bin/bash

# 定义变量方便修改
table_db=cy_database 
hive=/home/software/hive-2.3.6/bin/hive

# 如果是输入的日期按照取输入日期；如果没输入日期取当前时间的前一天
if [ -n "$1" ] ;then
	do_date=$1
else 
	do_date=`date -d "-1 day" +%F`  
fi 

sql="
with
tmp_out_work  as(
	select
		id,
		name,
		phone,
		birthday,
		idcard,
		sex,
		census_province_code,
		census_city_code,
		census_area_code,
		census_town_code,
		census_village_code,
		census_province,
		census_city,
		census_area,
		census_town,
		census_village,
		skill_specialty,
		skill_level,
		is_work,
		work_status,
		work_town_code,
		work_town,
		work_company,
		work_position,
		work_salary,
		out_work_address,
		out_work_company,
		out_work_position,
		out_date,
		is_back,
		out_salary ,
		ni_back_company,
		ni_positon,
		expect_salary, 
		remark,
		is_settle,
		education ,
		school,
		entrance_time,
		edu_time,
		graduation ,
		title_name,
		title_time,
		update_time
	from cy_database.dwd_out_work ow
	where ow.dt='2020-06-17' and ow.id is not null

)

insert overwrite table cy_database.dws_out_work  partition(dt='2020-06-17')
	select
		id,
		name,
		phone,
		birthday,
		idcard,
		sex,
		census_province_code,
		census_city_code,
		census_area_code,
		census_town_code,
		census_village_code,
		census_province,
		census_city,
		census_area,
		census_town,
		census_village,
		skill_specialty,
		skill_level,
		is_work,
		work_status,
		work_town_code,
		work_town,
		work_company,
		work_position,
		work_salary,
		out_work_address,
		out_work_company,
		out_work_position,
		out_date,
		is_back,
		out_salary,
		ni_back_company,
		ni_positon,
		expect_salary, 
		remark,
		is_settle,
		education,
		school,
		entrance_time,
		edu_time,
		graduation,
		title_name,
		title_time,
		update_time
	from tmp_out_work

;



"
$hive -e "$sql"